<template>
  <div class="parent-container">
    <div class="left-container">
      <LeftTopComponent
        @goback="goback"
        @storages="storages"
        @saves="saves"
        :tableData="tableData"
      />
      <LeftBottomComponent
        :tableData="answerdata"
        @addnewanswer="addnewanswer"
      />
    </div>
    <div class="right-container">
      <FormComponent @saveform="saveform" v-if="newaddanswer" />
    </div>
  </div>
</template>
<script>
// import ansyertempTab from "@/views/answertemplate/ansyertempTab.vue";

import LeftTopComponent from "@/views/answertemplate/LeftTopComponent.vue";
import LeftBottomComponent from "@/views/answertemplate/LeftBottomComponent.vue";
import FormComponent from "@/views/answertemplate/FormComponent.vue";
import { getnewanswerinfo } from "@/api/hubeixiaojin/queryInfo";
export default {
  name: "ParentComponent",
  props: ["tableData", "option"],
  components: {
    LeftTopComponent,
    LeftBottomComponent,
    FormComponent
  },
  data() {
    return {
      //添加的答题数据
      answerdata: {
        list: [] //默认为查看页面传输的数据
      },
      newaddanswer: false, //新增问题页面
      agentInfo: {
        //当前座席名字和id
        // dispatchingPerson: Constants.Agent.agentName,
        // dispatchingId: Constants.Agent.agentId,
        // //目标座席和id
        // agentId: "",
        // agentName: "",
        // //座席行政组
        // deptGroupName: Constants.Agent.deptGroupName,
        // //行政组code
        // deptGroupCode: Constants.Agent.deptGroupCode,
        // //access_token
        // access_token: Constants.Agent.access_token,
        // //tenantId
        // tenantId: Constants.Agent.tenantId,
        // //orgCode
        // orgCode: Constants.Agent.orgCode
      }, //调单用到的座席信息
      //查看模板问题的数据
      lockanswerdata: []
    };
  },
  mounted() {
    const sessionStr = sessionStorage.getItem("userInfo");
    const agentUser = JSON.parse(sessionStr);
    this.agentInfo = agentUser.content;

    if (this.tableData.typels && this.tableData.typels == "1") {
      //查看按钮进来的，接口获取该模板的详细信息
      this.getanswer();
      return;
    }
    if (this.tableData.typels && this.tableData.typels == "0") {
      //查看按钮进来的，接口获取该模板的详细信息
      this.getanswer();
      return;
    }
  },
  methods: {
    getanswer() {
      var params = {
        condition: {
          incomingPassage: this.tableData.incomingPassage
        },
        sortCol: "id"
      };
      getnewanswerinfo(params, this.agentInfo).then(res => {
        console.log("接口获取的模板详情==", res.data.data.listData[0]);
        this.lockanswerdata = res.data.data.listData[0].verifyQuestions;
        this.answerdata.list = this.lockanswerdata;
        // this.answerdata.id = res.data.data.listData[0].id;
        // console.log(
        //   "问题模板详情==",
        //   (this.answerdata.list)
        // );
      });
    },
    goback() {
      this.$emit("goback");
    },
    storages(val) {
      if (this.tableData.typels && this.tableData.typels == "1") {
        return window.globalUiKit.notify("提示", "查看时不可操作", "info");
      }
      //暂存按钮
      val.answerdata = this.answerdata.list;
      val.typels = this.tableData.typels || "";
      this.$emit("storages", val);
    },
    saves(val) {
      //保存按钮
      if (this.tableData.typels && this.tableData.typels == "1") {
        return window.globalUiKit.notify("提示", "查看时不可操作", "info");
      }
      val.answerdata = this.answerdata.list;
      // console.log("保存按钮需要添加编辑或者暂存标识符", this.tableData);
      val.typels = this.tableData.typels || "";
      val.id = this.tableData.id || "";
      this.$emit("saves", val);
    },
    //接收新增问题页面传来的数据
    getanswerdata(val) {
      this.answerdata.list.push(val);
      console.log("左下需要的数据1==", this.answerdata);
    },
    saveform(val) {
      console.log("接收保存的数据:", val);
      this.answerdata.list.push(val);
      this.newaddanswer = false;
      console.log("左下需要的数据2==", this.answerdata);
    },
    addnewanswer() {
      if (this.tableData.typels && this.tableData.typels == "1") {
        return window.globalUiKit.notify("提示", "查看时不可操作", "info");
      }
      //点击新增问题
      this.newaddanswer = true;
    }
  }
};
</script>

<style scoped>
.parent-container {
  display: flex;
  justify-content: space-between;
}

.left-container {
  width: 50%; /* 根据需要调整宽度 */
  display: flex;
  flex-direction: column;
  border-right: 1px solid #000000;
}

.right-container {
  width: 45%; /* 根据需要调整宽度，留一些间隙 */
}
</style>
